package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.domain.MessageReply;
import cn.wolfcode.mapper.MessageReplyMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageBoardService;
import cn.wolfcode.service.IMessageReplyService;
import cn.wolfcode.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageReplyServiceImpl implements IMessageReplyService {

    @Autowired
    private MessageReplyMapper messageReplyMapper;

    @Autowired
    private IMessageBoardService messageBoardService;
    @Override
    public void save(MessageReply messageReply) {
        Employee currentUser = UserContext.getCurrentUser();
        messageReply.setReplyUser(currentUser);
        messageReply.setCreateTime(new Date());
        //将状态设置成已经回复
        messageBoardService.changeReplystatus(messageReply.getMessageId());
        messageReplyMapper.insert(messageReply);
    }

    @Override
    public void delete(Long id) {
        messageReplyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(MessageReply messageReply) {
        messageReplyMapper.updateByPrimaryKey(messageReply);
    }

    @Override
    public MessageReply get(Long id) {
        return messageReplyMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MessageReply> listAll() {
        return messageReplyMapper.selectAll();
    }

    @Override
    public PageInfo<MessageReply> query(QueryObject qo) {
        return null;
    }
}
